package biz.obake.team.touchprotector.ui;

import android.content.Intent;
import android.content.res.Resources;
import android.graphics.drawable.Drawable;
import android.os.Bundle;
import androidx.preference.Preference;
import biz.obake.team.android.a;
import biz.obake.team.touchprotector.R;
import biz.obake.team.touchprotector.lfd.CurrentDesignPreference;
import biz.obake.team.touchprotector.lfd.LfdCustomActivity;
import biz.obake.team.touchprotector.lfd.LfdPackageActivity;
import biz.obake.team.touchprotector.lfd.LfdPresetActivity;
import biz.obake.team.touchprotector.lfd.c;
import biz.obake.team.touchprotector.lfd.d;
import biz.obake.team.touchprotector.lfd.f;

public class Tab_LockDesign extends a implements d.b {
    private void addDesignPackages() {
        for (c cVar : d.d().e()) {
            try {
                Preference preference = new Preference(getActivity());
                preference.y0(cVar.n());
                preference.v0(cVar.m());
                preference.o0(cVar.h());
                Intent intent = new Intent(a.a(), LfdPackageActivity.class);
                intent.putExtra("packageName", cVar.j());
                preference.p0(intent);
                getPreferenceScreen().G0(preference);
            } catch (c.b unused) {
            }
        }
    }

    private void updateCurrentDesignPreference() {
        Drawable drawable;
        Intent intent;
        f d2 = f.d();
        String g = d2.g();
        String f = d2.f();
        Drawable h = d2.h();
        String e = d2.e();
        if (h != null) {
            Resources resources = getResources();
            biz.obake.team.android.f fVar = new biz.obake.team.android.f(resources, (int) resources.getDimension(R.dimen.lfd_current_design_pref_thumbnail_size), (int) resources.getDimension(R.dimen.lfd_current_design_pref_thumbnail_size));
            fVar.d(h);
            drawable = fVar.c();
        } else {
            drawable = null;
        }
        CurrentDesignPreference currentDesignPreference = (CurrentDesignPreference) getPreferenceScreen().H0("current_design_preference");
        currentDesignPreference.v0(g + "\n" + f);
        currentDesignPreference.G0(drawable);
        if (e != null) {
            if (e.startsWith("preset:")) {
                intent = new Intent(a.a(), LfdPresetActivity.class);
            } else if (e.startsWith("custom:")) {
                intent = new Intent(a.a(), LfdCustomActivity.class);
            } else {
                String str = e.split(":", 2)[0];
                Intent intent2 = new Intent(a.a(), LfdPackageActivity.class);
                intent2.putExtra("packageName", str);
                currentDesignPreference.p0(intent2);
                return;
            }
            currentDesignPreference.p0(intent);
        }
    }

    public void onCreatePreferences(Bundle bundle, String str) {
        setPreferencesFromResource(R.xml.ui_tab_lockdesign, str);
        addDesignPackages();
    }

    public void onLfdPackageManagerChanged() {
        reloadSelf();
    }

    public void onPause() {
        super.onPause();
        d.d().i(this);
    }

    public void onResume() {
        super.onResume();
        d.d().g(this);
        d.d().h();
        updateCurrentDesignPreference();
    }
}
